package com.xujiakai.car.maintain.domain.entity;


import com.xujiakai.car.maintain.infrastructure.mapper.DaoFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class Partcategory {
    private Integer id;

    private String numbering;

    private String partcategory;

    private String partcatflag;

    @Resource
    private DaoFactory daoFactory;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNumbering() {
        return numbering;
    }

    public void setNumbering(String numbering) {
        this.numbering = numbering == null ? null : numbering.trim();
    }

    public String getPartcategory() {
        return partcategory;
    }

    public void setPartcategory(String partcategory) {
        this.partcategory = partcategory == null ? null : partcategory.trim();
    }

    public String getPartcatflag() {
        return partcatflag;
    }

    public void setPartcatflag(String partcatflag) {
        this.partcatflag = partcatflag == null ? null : partcatflag.trim();
    }

    public boolean modifyPartCategory(com.xujiakai.car.maintain.domain.dto.PartcategoryDTO partcategory, String type) {
        boolean flag = false;
        if (partcategory != null && org.apache.commons.lang.StringUtils.isNotBlank(type)) {
            if ("C".equals(type)) {// 添加
                partcategory.setPartcatflag("1");
                flag = daoFactory.getPartcategoryMapper().insertSelective(partcategory) > 0;
            } else if ("U".equals(type)) {// 修改
                flag = daoFactory.getPartcategoryMapper().updateByPrimaryKeySelective(partcategory) > 0;
            } else if ("D".equals(type)) {// 删除
                com.xujiakai.car.maintain.domain.dto.PartcategoryDTO pt = daoFactory.getPartcategoryMapper().selectByPrimaryKey(partcategory.getId());
                if (pt != null) {
                    pt.setPartcatflag(partcategory.getPartcatflag());
                    flag = daoFactory.getPartcategoryMapper().updateByPrimaryKeySelective(pt) > 0;
                }
            }
        }
        return flag;
    }
}